package com.yxym.homework;

public class Homework01 {
    public static void main(String[] args) {
        /*
        * 1.将字符串中指定部分进行反转，比如将“abcdef"反转为”aedcbf
        * 2.编写方法
        * 3.
         */
        String string = "abcdef";
        System.out.println(string);
        System.out.println("=====");
        String string2 = null;
        try {
            string2 = reverse(string, 4, 4);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return;
        }
        //System.out.println("=========");
        System.out.println(string2);
    }
    public static String reverse(String string ,int start,int end){
        //对输入的参数进行验证
        //1.先写出正确的
        //2.然后取反
        if(!(string != null && start >= 0 && end > start && end < string.length())){
            throw new RuntimeException("===参数不正确===");
        }
        char[] chars = string.toCharArray();
        char temp = ' ';//变换辅助变量
        for(int i = start ,j = end ; i < j ; i++,j--){
            temp = chars [i];
            chars[i] = chars[j];
            chars[j] = temp;
        }
        return new String(chars);
    }
}
